home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / awe2-0_1.lha / awe2-0.1 / Src / Erlang.h < prev    next >
C/C++ Source or Header  |  1989-10-19  |  2KB  |  73 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /* 
  3. Copyright (C) 1988 Free Software Foundation
  4.     written by Dirk Grunwald (grunwald@cs.uiuc.edu)
  5.  
  6. This file is part of GNU CC.
  7.  
  8. GNU CC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY.  No author or distributor
  10. accepts responsibility to anyone for the consequences of using it
  11. or for whether it serves any particular purpose or works at all,
  12. unless he says so in writing.  Refer to the GNU CC General Public
  13. License for full details.
  14.  
  15. Everyone is granted permission to copy, modify and redistribute
  16. GNU CC, but only under the conditions described in the
  17. GNU CC General Public License.   A copy of this license is
  18. supposed to have been given to you along with GNU CC so you
  19. can know your rights and responsibilities.  It should be in a
  20. file named COPYING.  Among other things, the copyright notice
  21. and this notice must be preserved on all copies.  
  22. */
  23. #ifndef _Erlang_h
  24. #define _Erlang_h 1 
  25. #pragma once
  26.  
  27. #include <Random.h>
  28.  
  29. class Erlang: public Random {
  30.     double pMean;
  31.     double pVariance;
  32.     int k;
  33.     double a;
  34.     void setState();
  35. public:
  36.     Erlang(double mean, double variance, RNG *gen);
  37.  
  38.     double mean();
  39.     double mean(double x);
  40.     double variance();
  41.     double variance(double x);
  42.  
  43.     virtual double operator()();
  44.  
  45. };
  46.  
  47. //#ifdef __OPTIMIZE__
  48.  
  49. inline void Erlang::setState() {
  50.   k = int( (pMean * pMean ) / pVariance + 0.5 );
  51.   k = (k > 0) ? k : 1;
  52.   a = k / pMean;
  53. }
  54.  
  55. inline Erlang::Erlang(double mean, double variance, RNG *gen) : (gen)
  56. {
  57.   pMean = mean; pVariance = variance;
  58.   setState();
  59. }
  60.  
  61. inline double Erlang::mean() { return pMean; }
  62. inline double Erlang::mean(double x) {
  63.   double tmp = pMean; pMean = x; setState(); return tmp;
  64. };
  65.  
  66. inline double Erlang::variance() { return pVariance; }
  67. inline double Erlang::variance(double x) {
  68.   double tmp = pVariance; pVariance = x; setState(); return tmp;
  69. }
  70.  
  71. //#endif
  72. #endif
  73.